﻿using System;
using System.Windows.Forms;
using System.Drawing;

namespace LocationAwareness
{
    /// <summary>
    /// Category Box, showing different categories the user can filter for.
    /// </summary>
    class CatBox : PictureBox
    {
        private bool pressed = false;

        public CatBox()
        {
            this.Image = global::LocationAwareness.Resources.button;
        }

        private string text;

        /// <summary>
        /// Setting the text of the filter.
        /// </summary>
        public string TextOnPicture
        {
            set
            {
                text = value;
            }

            get
            {
                return text;
            }
        }

        /// <summary>
        /// Shows if filter category is choosen or not.
        /// </summary>
        public bool Pressed
        {
            get
            {
                return pressed;
            }
        }

        /// <summary>
        /// Event method occurs when CatBox is clicked.
        /// </summary>
        protected override void OnClick(EventArgs e)
        {
            if (!pressed)
            {
                pressed = true;
                this.Image = global::LocationAwareness.Resources.pressedButton;
            }
            else
            {
                pressed = false;
                this.Image = global::LocationAwareness.Resources.button;
            }
            base.OnClick(e);
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics g = e.Graphics;
            Rectangle rec = ClientRectangle;

            StringFormat stringFormat = new StringFormat();
            stringFormat.Alignment = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;

            Font f = new Font("Tahoma", 9, FontStyle.Bold);
            Brush b = new SolidBrush(Color.Black);
            g.DrawString(text, f, b, rec, stringFormat);
        }

        /// <summary>
        /// Checks Filter of CatBox.
        /// </summary>
        public void CheckFilter()
        {
            pressed = true;
            this.Image = global::LocationAwareness.Resources.pressedButton;
        }

        /// <summary>
        /// Unchecks Filter of CatBox.
        /// </summary>
        public void UncheckFilter()
        {
            pressed = false;
            this.Image = global::LocationAwareness.Resources.button;
        }
    }
}
